package com.zq.common.logs;

import com.alibaba.fastjson.JSON;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.net.http.HttpClient;

/**
 * @Author 张乔
 * @Date 2024/5/30 13:25
 */

public class LogService {


public static void send(SysOperLog sysOperLog){
    // 创建 RestTemplate 对象
    RestTemplate restTemplate = new RestTemplate();

    // 设置请求头
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);


    // 假设使用 Gson 来转换对象为 JSON 字符串
    String jsonBody = JSON.toJSONString(sysOperLog);

    // 创建 HttpEntity 对象，并设置请求体和请求头
    HttpEntity<String> requestEntity = new HttpEntity<>(jsonBody, headers);

    // 发送 POST 请求
    ResponseEntity<String> responseEntity = restTemplate.
            postForEntity("http://localhost:8500/sys/logs/save", requestEntity, String.class);

    // 处理响应
    System.out.println("Response status: " + responseEntity.getStatusCode());
    System.out.println("Response body: " + responseEntity.getBody());


}


}
